package com.tangyuan.user.controller;

import com.github.pagehelper.PageInfo;
import com.tangyuan.common.exception.TangYuanException;
import com.tangyuan.common.result.Result;
import com.tangyuan.user.service.impl.UserArticleSearchImpl;
import com.tangyuan.user.service.impl.UserInfoSearchImpl;
import com.tangyuan.user.service.impl.UserVideoSearchImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/user")
public class UserSearchController {

    @Autowired
    UserArticleSearchImpl userArticleSearch;
    @Autowired
    UserInfoSearchImpl userInfoSearch;
    @Autowired
    UserVideoSearchImpl userVideoSearch;


    //用户搜索 其他用户 视频 文章
    @GetMapping("/search")
    public Result userSearch(@RequestParam Integer type,
                             @RequestParam Integer pageNum,
                             @RequestParam Integer pageSize,
                             @RequestParam String name,
                             @RequestHeader(name = "Authorization",required = false) String token) {
        if (type == 0) {
            return userInfoSearch.userSearch(pageNum, pageSize, name, token);
        } else if (type == 2) {
            return userVideoSearch.userSearch(pageNum, pageSize, name, token);
        } else if (type == 1) {
            return userArticleSearch.userSearch(pageNum, pageSize, name, token);
        }
        return Result.ok(new PageInfo<>());
    }
}
